unit frmConfPath;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, jpeg, ExtCtrls, Buttons, Registry;

type
  TF_ConfPath = class(TForm)
    btnGravar: TBitBtn;
    btnTeste: TBitBtn;
    Image1: TImage;
    EditBase: TEdit;
    EditLogin: TEdit;
    EditSenha: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Dialog: TOpenDialog;
    procedure btnTesteClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure EditBaseDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_ConfPath: TF_ConfPath;

implementation

uses frmDMGeral;

{$R *.dfm}


procedure TF_ConfPath.btnTesteClick(Sender: TObject);
begin
  try
    with DMGeral.Conexao do begin
      Close;
      DatabaseName := EditBase.Text;
      with Params do begin
        Clear;
        Add('user_name=' + EditLogin.Text);
        Add('password=' + EditSenha.Text);
      end;
      Open;
      ShowMessage('Conectado com sucesso!');
      BtnGravar.Enabled := True;
    end;
  except
    on e: Exception do begin
      BtnGravar.Enabled := False;
      ShowMessage('Erro:' + #13 + e.Message);
    end;
  end;
end;

procedure TF_ConfPath.FormCreate(Sender: TObject);
var
  oReg: TRegistry;
begin
  oReg := TRegistry.Create;
  try
    if oReg.OpenKey('Software\MultForms Software\Legourmet', False) then begin
      EditBase.Text  := oReg.ReadString('DB');
      EditLogin.Text := oReg.ReadString('US');
      EditSenha.Text := oReg.ReadString('PS');
      oReg.CloseKey;
      Close;
    end;
  finally
    oReg.Free;
  end;
end;

procedure TF_ConfPath.btnGravarClick(Sender: TObject);
var
  oReg: TRegistry;
begin
  oReg := TRegistry.Create;       
  try
    if oReg.OpenKey('Software\MultForms Software\ALFood', True) then begin
      oReg.WriteString('DB', EditBase.Text);
      oReg.WriteString('US', EditLogin.Text);
      oReg.WriteString('PS', EditSenha.Text);
      oReg.CloseKey;
      Close;
    end;
  finally
    oReg.Free;
  end;
end;

procedure TF_ConfPath.EditBaseDblClick(Sender: TObject);
begin
  Dialog.Execute;
  EditBase.Text := Dialog.FileName;
  Dialog.Free;
end;

end.
